<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<s:head theme="ajax" debug="true"/>
		<script type="text/javascript">
			dojo.event.topic.subscribe("/save", function(data, type, request) {
			    if(type == "load") {
					dojo.byId("userId").value = "";
					dojo.byId("userName").value = "";
					dojo.byId("password").value = "";
				}
			});

			dojo.event.topic.subscribe("/edit", function(data, type, request) {
			    if(type == "before") {
					var userId = data.split("_")[1];
					
					var tr = dojo.byId("row_"+userId);
					var tds = tr.getElementsByTagName("td");

					dojo.byId("userId").value = userId;
					dojo.byId("userName").value = dojo.string.trim(dojo.dom.textContent(tds[0]));
					dojo.byId("password").value = dojo.string.trim(dojo.dom.textContent(tds[1]));
					dojo.byId("email").value = dojo.string.trim(dojo.dom.textContent(tds[2]));
					dojo.byId("sex").value = dojo.string.trim(dojo.dom.textContent(tds[3]));
					dojo.byId("profile").value = dojo.string.trim(dojo.dom.textContent(tds[4]));
					dojo.byId("description").value = dojo.string.trim(dojo.dom.textContent(tds[5]));
					dojo.byId("createTime").value = dojo.string.trim(dojo.dom.textContent(tds[6]));
					dojo.byId("rankId").value = dojo.string.trim(dojo.dom.textContent(tds[7]));
				}
			});
		</script>
	</head>
	<body>
	    <s:url action="list" id="descrsUrl"/>

        <div style="width: 300px;border-style: solid">
        	<div style="text-align: right;">
    			<s:a theme="ajax" notifyTopics="/refresh">Refresh</s:a>
    		</div>
    		<s:div id="users" theme="ajax" href="%{descrsUrl}" loadingText="Loading..." listenTopics="/refresh"/>
        </div>

        <br/>

		<div style="width: 300px;border-style: solid">
			<p>User Data</p>
			<s:form action="save" validate="true">
			    <s:textfield id="userId" name="user.userId" cssStyle="display:none"/>
				<s:textfield id="userName" label="User Name" name="user.userName"/>
				<s:textfield id="password" label="Password" name="user.password"/>
				<s:hidden id="email" name ="user.email"/>
				<s:hidden id="sex" name ="user.sex"/>
				<s:hidden id="profile" name ="user.profile"/>
				<s:hidden id="description" name ="user.description"/>
				<s:textfield id="createTime" label="CreateTime" name="user.createTime"/>
				<s:textfield id="rankId" label="RankId" name="user.rankId"/>
				<s:submit theme="ajax" targets="users" notifyTopics="/save"/>
				<s:reset></s:reset>
			</s:form>
		</div>
	</body>
</html>
